<?php

function is_valid_email($email) {
  $result = TRUE;
  if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $email)) {
    $result = FALSE;
  }
  return $result;
}

function getNextValSeq($seqName) {

	include('Connections/CSRE_Connection.php'); 
	
	mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
	$query_nextValeSeq = sprintf("SELECT * FROM csre_sequence where seq_name = '%s'", $seqName);
	$nextValeSeq = mysql_query($query_nextValeSeq, $CSRE_Connection) or die(mysql_error());
	$row_nextValeSeq = mysql_fetch_assoc($nextValeSeq);
	$totalRows_nextValeSeq = mysql_num_rows($nextValeSeq);
	
	$nextVal = $row_nextValeSeq['seq_value'];
	
	$query_updateValeSeq = sprintf("UPDATE csre_sequence set seq_value = %s where seq_name = '%s'", $nextVal + 1, $seqName);
	$updateValeSeq = mysql_query($query_updateValeSeq, $CSRE_Connection) or die(mysql_error());
	
	mysql_free_result($nextValeSeq);
	
	return $nextVal;

}

function getValor($param) {

	if (isset($_GET[$param])) {
		return $_GET[$param];
	} else if (isset($_POST[$param])) {
		return $_POST[$param];
	}
	return "";
	
}

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

?>